package cn.tedu.springmvc.controller;

import cn.tedu.springmvc.mapper.UserInfoMapper;
import cn.tedu.springmvc.pojo.dto.UserDto;
import cn.tedu.springmvc.pojo.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @RequestMapping("/regUser")
    @ResponseBody
    //public String regUser(HttpServletRequest request){
    //    String username=request.getParameter("username");
    //    String password=request.getParameter("password");
    //    String nickname=request.getParameter("nickname");
    //    String age=request.getParameter("age");
    //    System.out.println("开始处理用户注册！！！！！！！！！！！！！！！！");
    //    System.out.println(username+","+password+","+nickname+","+age);
    //    return "注册成功!";
    //  }
    /*public String regUser(String username,String password,String nickname,int age){
        System.out.println("开始处理注册");
        System.out.println(username+","+password+","+nickname+","+age);
        return "注册成功";
    }

     */
    public String regUser(UserDto userDto){
        System.out.println("开始处理注册");
        System.out.println(userDto);
        UserInfo userInfo=new UserInfo();
        userInfo.setUsername(userDto.getUsername());
        userInfo.setPassword(userDto.getPassword());
        userInfo.setNickname(userDto.getNickname());
        userInfo.setAge(userDto.getAge());
        int num=userInfoMapper.insertUserInfo(userInfo);
        System.out.println(num>0?"插入成功":"插入失败");
        return "注册成功！";
    }
}
